package micro86.engine;

/**
 * (c) Kate Luzhevskaya 2013
 */

public class State {
    // general purpose registers
    class Registers{
        private int ax;
        private int bx;
        private int cx;
    }
    class Flags {
        private boolean sf; // sign flag: 0 - positive; 1 - negative
        private boolean zf; // zero flag: 0 - non-zero; 1 - zero
        private boolean of = true; // always zero
    }

    private Registers registers;
    private Flags flags;
    private int ip; // instruction pointer


    public int getAX() {
        return registers.ax;
    }
    public void setAX(int value) {
        registers.ax = value;
    }
    public int getBX() {
        return registers.bx;
    }
    public void setBX(int value) {
        registers.bx = value;
    }
    public int getCX() {
        return registers.cx;
    }
    public void setCX(int value) {
        registers.cx = value;
    }

    public boolean getSF() {
        return flags.sf;
    }
    public void setSF(boolean value) {
        flags.sf = value;
    }

    public void setSFbyResult(int res) {
        if (res >= 0) {
            setSF(false);
        }
        else {
            setSF(true);
        }
    }

    public boolean getZF() {
        return flags.zf;
    }
    public void setZF(boolean value) {
        flags.zf = value;
    }

    public void setZFByResult(int res) {
        if (res == 0) {
            setZF(true);
        }
        else {
            setZF(false);
        }
    }

    public boolean getOF() {
        return flags.of;
    }

    public int getIP() {
        return ip;
    }
    public void setIP(int value) {
        ip = value;
    }
    public void incIP() {
        ++ip;
    }
    public void invalidateIP() {
        setIP(-1);
    }



    public State() {
        this.registers = new Registers();
        this.flags = new Flags();
    }

    public void reset() {
        setAX(0);
        setBX(0);
        setCX(0);
        setSF(false);
        setZF(false);
        setIP(0);
    }
}
